<template name='person_admin'>

<view style="display: flex;    height: 100%;">

	<!-- 商品信息-右边 -->
	<view class="box-infos font12  " >
		<!-- 数据列表 -->
		<view class="content-box">
			<view class="boxsss40" >
				<!-- 增加、删除 -->
				<view class="top-but menu-scroll-w" v-if="OnPageSearchUserId.length<=0">
					<view class="top-but-box">
						<view 
						@click="$common.noMultipleClicks('batchPrevent',batchPrevent)" 
						class="add_color but-add " 
						v-if="status=='user_process'"
						>
							<img src="../../static/img/add.png" class="img"></img>
							全部通过审核
						</view>
						<text selectable="true"  v-if="status=='user_process'" class="tipss">新增加的客户需要需要在此处神经审核后，客户账号方可正常使用</text>
				
						<view class=" maxwidth250 flex floatleft" 
							v-if="status=='firm_user_list' && sendType=='kh'"
						>
							<view class="riskTitle">选择线路:</view>
							<uni-data-select
							:localdata="$routeData.getRoute()"
							v-model="headerSearch.route_id"
							@change="(e)=>{$routeData.SetNowRoute(e),formsubmit(e)}"
							placeholder="选择仓库线路"
							placeholder-class="placeholder-class"
							class="color-e40318"
							></uni-data-select>
						</view>
						<view class=" maxwidth250 flex floatleft" 
						v-if="status=='firm_user_list' && sendType=='kh'"
						>
							<view class="riskTitle">用户分组:</view>
							<uni-data-select
							:localdata="$routeData.getGroup()"
							v-model="headerSearch.group_id"
							@change="(e)=>{$global.setStorageRoute('group',e),formsubmitGroup(e)}"
							placeholder="选择用户分组"
							placeholder-class="placeholder-class"
							class="color-e40318"
							></uni-data-select>
						</view>
				
						<view class=" maxwidth250 flex floatleft" 
						v-if="status=='firm_user_list' && sendType=='kh'"
						>
							<view class="riskTitle">价格等级:</view>
							<uni-data-select
							:localdata="$routeData.getLevel()"
							v-model="headerSearch.level_id"
							@change="(e)=>{$global.setStorageRoute('level_id',e),formsubmitLevel(e)}"
							placeholder="选择价格等级"
							placeholder-class="placeholder-class"
							class="color-e40318"
							></uni-data-select>
						</view>
						<!-- 搜索 -->
						<view class="floatleft flex" v-if="status=='firm_user_list' ">
							<view class="riskTitle">客户名称:</view>
							<view class="searchBoxs " >
								<input
								v-model="headerSearch.word" 
								placeholder="输入客户档口 人名 手机 拼音进行搜索"
								placeholder-class="placeholder-class"
								@confirm="$common.noMultipleClicks('searchBut',searchBut,true)"
								class="search-ipu "
								/>
								<view class="delete-ipu" v-if="headerSearch.word!=''" @click="headerSearch.word=''">
									<img src="../../static/img/delete-1.png"></img>
								</view>
							</view>
						</view>
						<view @click="$common.noMultipleClicks('searchBut',searchBut,true)" 
						:class="status=='firm_user_list' ?'':'margin-left'"
						class="add_color search-but" >
							<img src="../../static/img/search.png" class="img" ></img>
							刷新
						</view>
						
						<button 
						v-if="status=='firm_user_list'"
						@click="addShow()"
						class="add_color but-add margin-left"
						>
							<img src="../../static/img/add.png" class="img"></img>
							增加(手动模式)
						</button>
						
						<button
						v-if="status=='firm_user_list' && (sendType=='kh' || sendType=='gys')"
						@click="$refs.excel_r.open()"
						class="leftBut   color7" 
						>
							增加(Excel模式)
						</button>
						
						<button
						@click="$my_excel.user(resData.list,false)"
						class="nowBut color7 font12"
						>
							导出
						</button>
					</view>
				</view>

				<table v-if="resData.list!=undefined && resData.list.length>0">
					<!-- 表头 -->
					<thead>
						<tr >
							<th class="centers ">
								<checkbox
									border-color="#333333" activeborderColor="#333333" activeBackgroundColor="#333"
									:checked="checkbox.select" 
									@click="choose_all"
									style="transform:scale(0.7);"
								/>
								
							</th>
							<th class="centers">
								序
							</th>
							<th class="">
								账号名称
							</th>
							<th class="centers" >
								授信额度
							</th>
							<th class=" " >
								<view class="flex ">
									
									余额
									<view class="sort-button">
										<view class="desc"  @click="sort.value='moneyDesc',loadData(true)"></view>
										<view class="asc"   @click="sort.value='moneyAsc',loadData(true)"></view>
									</view>
								</view>
							</th>
							<th class=" " v-if="sendType=='kh'">
								<view class="flex ">
									销售
									<view class="sort-button">
										<view class="desc"  @click="sort.value='SalesDesc',loadData(true)"></view>
										<view class="asc"   @click="sort.value='SalesAsc',loadData(true)"></view>
									</view>
								</view>
							</th>

							<th class=" "v-if="sendType=='kh'">
								<view class="flex ">
									积分
									<view class="sort-button">
										<view class="desc"  @click="sort.value='scoreDesc',loadData(true)"></view>
										<view class="asc"   @click="sort.value='scoreAsc',loadData(true)"></view>
									</view>
								</view>
							</th>
							<th class=" ">
								<view class="flex centers">
									线路
									<view class="sort-button">
										<view class="desc"  @click="sort.value='routeDesc',loadData(true)"></view>
										<view class="asc"   @click="sort.value='routeAsc',loadData(true)"></view>
									</view>
								</view>
							</th>
							<th class=" ">
								<view class="flex centers">
									地图
									<view class="sort-button">
										<view class="desc"  @click="sort.value='MapDesc',loadData(true)"></view>
										<view class="asc"   @click="sort.value='MapAsc',loadData(true)"></view>
									</view>
								</view>
							</th>
							
							<th class=" "v-if="sendType=='kh'">
								<view class="flex centers">
									用户分组
									<view class="sort-button">
										<view class="desc"  @click="sort.value='groupDesc',loadData(true)"></view>
										<view class="asc"   @click="sort.value='groupAsc',loadData(true)"></view>
									</view>
								</view>
							</th>
							
							<th class=" "v-if="sendType=='kh'">
								<view class="flex centers">
									价格等级
								</view>
							</th>
							<th class=" "v-if="sendType=='kh'">
								<view class="flex centers">
									拜访时间
									<view class="sort-button">
										<view class="desc"  @click="sort.value='SalesOrderDateDesc',loadData(true)"></view>
										<view class="asc"   @click="sort.value='SalesOrderDateAsc',loadData(true)"></view>
									</view>
								</view>
							</th>
							
							<th class="centers "v-if="sendType=='kh'">
								开单时间
							</th>
							<th class="centers ">
								注册时间
							</th>
						</tr>
					</thead>
					<tbody>
						<checkbox-group @change="checkbox_change" style="display: contents;">
						<!-- 内容 -->
						<tr v-for="(item,index) in resData.list" 
						:key="index"
						:class="checkbox.checkbox_status.includes(item.id)||TabcheckedIndex==index ? 'goods-list-select':''"
						:style="{color:item.prevent==1 ?'' : (item.prevent==2 ? '#f00' : item.prevent==3 ? '#001fff':'')}"
						@click="TabcheckedIndex=index"
						>
							<td class="centers  font12">
								<checkbox  class="centers  font12 "
									:value="item.id.toString()" 
									border-color="#333333" activeborderColor="#333333" 
									activeBackgroundColor="#333"
									:checked="checkbox.checkbox_status.includes(item.id)" 
									style="transform: scale(0.7);margin: auto;display: flex;"
								/>
							</td>
							<td class="centers  font12">
								<view class="centers  font12">
									{{item.number+'-'+item.id}} 
								</view>
							</td>
							<td selectable="true" class="  relative"  >
								<text selectable="true">{{item.name}}</text>
								<view class="back_data">
									
									<image src="/static/img/disabled.png"
									class="ico" v-if="item.disabled.status==true"
									:title="$global.title.m36"
									></image>
								</view>
							</td>
							
							<td class="centers">
								<input
								:auto-height="true"
								v-model="item.debt" 
								@confirm="$routeData.updateDebt(item.id,item.debt)"
								class="centers white-space  font12"
								/>
							</td>
							
							<td class=" " :class="item.sum_money>item.debt ?'color-e40318':''">
								￥{{item.sum_money}}
							</td>
							<td class="  alter " @click="openPageUserData(item.name,item.id)" v-if="sendType=='kh'">
								￥{{item.orderSales}}
							</td>
							

							<td class=" alter " 
							@click="openPageUserScore(item.name,item.id)"
							v-if="sendType=='kh'"
							>
								{{item.score}}
							</td>
							<td class="centers  font12">
								{{$routeData.GetRouteItem(item.route_id).text}}
							</td>
							<td class="centers  font12">
								{{item.latlng.length<=0 ? '':'有'}}
							</td>
							<td class="centers "
							v-if="sendType=='kh'">
								{{$routeData.GetGroupItem(item.group_id).text}}
							</td>
							
							<td class="centers "
							v-if="sendType=='kh'">
								<text>
									{{$routeData.GetLevelItem(item.level_id).text}}
								</text>
								<text>[{{$common.formatTime(item.level_date_end)}}]</text>
							</td>

							<td selectable="true"  
							class="centers  font12" 
							@click="$common.noMultipleClicks('openCalendar',openCalendar,item.id)"
							v-if="sendType=='kh'">
								
								<view selectable="true" 
								class="centers "
								v-if="item.SignIn.days>=0" 
								>
									{{item.SignIn.days}}天前
								</view>
							</td>
						
							<td selectable="true"  
							class="centers  font12" 
							v-if="sendType=='kh'">
								<view selectable="true" 
								class="centers "
								v-if="item.orderEnd.days>=0" 
								>
									{{item.orderEnd.days}}天前
								</view>
							</td>
							
							<td class="centers ">
								{{item.date}}
							</td>
						</tr>
						</checkbox-group>
					</tbody>
				</table>
				
				<!-- 暂无数据 -->
				<empty v-if="resData.list==undefined || resData.list.length==0"></empty>
				<!-- end -->
				
				
				<!-- 更多 -->
				<view class="xd-main flex sticky-bottom" v-if="TabcheckedIndex >= 0" >
					<view class="w100 flex xd-box" style="overflow: visible;">
						<button class="but but-color1 color1"
						:disabled="checkUpdate.isSelectAll==true"
						v-if="checkUpdate.Mode==-1"
						@click="alter(resData.list[TabcheckedIndex],TabcheckedIndex)">
							详细/设置
						</button>
						
						
						<button class="but but-color1 color10"  
						:disabled="checkUpdate.isSelectAll==true"
						v-if="checkUpdate.Mode==-1"
						@click="$common.GetInviteQrcode(resData.list[TabcheckedIndex].id)">
							
							{{resData.list[TabcheckedIndex].openidIsBind==true? '微信解绑':'绑定微信'}}
						</button>
						
						<button class="but but-color1 color2"  
						:disabled="checkUpdate.isSelectAll==true"
						v-if="checkUpdate.Mode==-1"
						@click="openPageUserDescr(resData.list[TabcheckedIndex].name,resData.list[TabcheckedIndex].id)">
							备忘录
						</button>
						
						
						
						<button class="but but-color1 color3" 
						@click="checkUpdateOpen(2)">
							移动用户分组
						</button>
						
						<view class="input_confirms maxwidth250 floatleft" v-if="checkUpdate.Mode==2">
							<uni-data-select
							:localdata="$routeData.getGroup()"
							v-model="checkUpdate.value"
							placeholder="选择账号分组"
							class="color-e40318"
							placeholder-class="placeholder-class"
							></uni-data-select>
						</view>
						
						<button class="but but-color1 color4"
						v-if="checkUpdate.Mode==2"
						
						@click="checkboxuserUpdateCheck()">
							确定保存
						</button>
						<button class="but but-color1 color1"
						
						v-if="checkUpdate.Mode==2"
						@click="checkUpdate.Mode=-1">
							取消
						</button>
						
						
						<button class="but but-color1 color4" 
						v-if="checkUpdate.Mode==-1"
						@click="checkUpdateOpen(3)">
							移动价格分组
						</button>
						
						<view class="input_confirms maxwidth250 floatleft" v-if="checkUpdate.Mode==3">
							<uni-data-select
							style="max-width: 300px;"
							:localdata="$routeData.getLevel()"
							v-model="checkUpdate.value"
							placeholder="选择价格等级"
							class="color-e40318"
							placeholder-class="placeholder-class"
							></uni-data-select>
						</view>
						<button class="but but-color1 color1"
						v-if="checkUpdate.Mode==3"
						@click="checkboxuserUpdateCheck()">
							确定保存
						</button>
						<button class="but but-color1 "
						v-if="checkUpdate.Mode==3"
						@click="checkUpdate.Mode=-1">
							取消
						</button>
						
						
						<button class="but but-color1 color5"  
						v-if="checkUpdate.Mode==-1"
						@click="checkUpdateOpen(1)">
							移动所属线路
						</button>
						
						<view class="input_confirms maxwidth250 floatleft" v-if="checkUpdate.Mode==1">
							<uni-data-select
							style="max-width: 300px;"
							:localdata="$routeData.getRoute()"
							v-model="checkUpdate.value"
							placeholder="选择仓库线路"
							placeholder-class="placeholder-class"
							class="color-e40318"
							></uni-data-select>
						</view>
						
						<button class="but but-color1 color1"
						v-if="checkUpdate.Mode==1"
						
						@click="checkboxuserUpdateCheck()">
							确定保存
						</button>
						
						<button class="but but-color1 "
						v-if="checkUpdate.Mode==1"
						
						@click="checkUpdate.Mode=-1">
							取消
						</button>
						
						
						<button class="but but-color1 color6"  
						v-if="checkUpdate.Mode==-1"
						:disabled="checkUpdate.isSelectAll==true"
						@click="openPageUserGoodsRecord(resData.list[TabcheckedIndex].name,resData.list[TabcheckedIndex].id)">
							商品记录
						</button>
						
						<button class="but but-color1 color7"  
						v-if="checkUpdate.Mode==-1"
						:disabled="checkUpdate.isSelectAll==true"
						@click="openPageMoney(resData.list[TabcheckedIndex].name,resData.list[TabcheckedIndex].id)">
							历史单据
						</button>
						
						<button class="but but-color1 color8"  
						v-if="checkUpdate.Mode==-1"
						:disabled="checkUpdate.isSelectAll==true"
						@click="openPageVerifyOrdero(resData.list[TabcheckedIndex].name,resData.list[TabcheckedIndex].id)">
							单据流水
						</button>
						
						<button class="but but-color1 color9" 
						v-if="checkUpdate.Mode==-1"
						:disabled="checkUpdate.isSelectAll==true" 
						@click="openPageUserData(resData.list[TabcheckedIndex].name,resData.list[TabcheckedIndex].id)">
							每月数据
						</button>
						
						<button class="but but-color1 color10"  
						v-if="checkUpdate.Mode==-1"
						:disabled="checkUpdate.isSelectAll==true"
						@click="openGoodsMarkRecord(resData.list[TabcheckedIndex].name,resData.list[TabcheckedIndex].id)">
							浏览足迹
						</button>
							
						<button class="but but-color1 color1"  
						v-if="checkUpdate.Mode==-1"
						:disabled="checkUpdate.isSelectAll==true"
						@click="openPageUserScore(resData.list[TabcheckedIndex].name,resData.list[TabcheckedIndex].id)">
							用户积分记录
						</button>
						
						
						<button class="but but-color1 color2"  
						v-if="checkUpdate.Mode==-1"
						:disabled="checkUpdate.isSelectAll==true"
						@click="openGoodsDisabled(resData.list[TabcheckedIndex].name,resData.list[TabcheckedIndex].id)">
							禁售列表
						</button>
						
						<button class="but but-color3 color3"   
						v-if="checkUpdate.Mode==-1"
						@click="openActionSheet(resData.list[TabcheckedIndex],TabcheckedIndex,$event)"
						>
							更多操作
						</button>
						
						
						<view class="flex margin-left gap10">
							<view class="flex margin nowrap" @click="GetSum('getDebt')" :title="sumData.getDebt.value">
								<text class="right3">余额：</text>
								<text class="alter">
									{{sumData.getDebt.value.length<=0?'计算':$common.formatNumber(sumData.getDebt.value)}}
								</text>
							</view>
							
							<view class="flex margin nowrap" @click="GetSum('getSales')" :title="sumData.getSales.value">
								<text class="right3">销量</text>
								<text class="alter">
									{{sumData.getSales.value.length<=0?'计算':$common.formatNumber(sumData.getSales.value)}}
								</text>
							</view>
							
							
							<view class="flex margin nowrap" @click="GetSum('getScore')":title="sumData.getScore.value">
								<text class="right3">积分</text>
								<text class="alter">
									{{sumData.getScore.value.length<=0?'计算':$common.formatNumber(sumData.getScore.value)}}
								</text>
							</view>
						</view>
					</view>
				</view>
				<!-- 更多 end -->
				
			</view>

			<!-- end -->
			
			<pages 
			:sum="page.sum"
			:current="page.nowPage"
			@updatePage="updatePage"
			></pages>

		</view>
		<!-- 数据列表end -->
	
	</view>
	
	<!-- 数据导入  -->
	<uni-popup ref="excel_r" type="center" title="数据导入">

		<excel
		 uploadTypeName="user_add"
		 :uploadBodyPush="sendType=='kh' ? {firm_user:0}:{firm_user:2}"
		></excel>

	</uni-popup>
	<!-- end -->
	 <!-- 拜访弹窗 -->
	<uni-popup ref="calendar" type="center" title="拜访记录">
		<uni-calendar  class="h100" v-if="signInData.SignIn" :date="signInData.SignIn.date" :selected="signInData.list"/>
	</uni-popup>
	 <!-- end -->


	<!-- 增加/修改 客户 遮罩层 -->
	<uni-popup ref="popup" type="center" title="用户信息"  minWidth="auto">
	<!-- 商品信息-右边 -->
		<view class="box-infos font12" >
			<!-- 数据列表 -->
			<view class="content-box">
				<view class="boxsss100" >
					<view class="add-box">
						<view class="add-goods">
							账号类型：
							<view class="pop-input ">
								<uni-data-select
								@change="(e)=>{$routeData.SetNowRoute(e)}"
								:localdata="firmUserSelect.list"
								v-model="add.data.firm_user"
								placeholder="选择"
								placeholder-class="placeholder-class"
								></uni-data-select>
							</view>
						</view>
					</view>
					<view class="add-box" v-if="sendType!='gys' ">
						<view class="add-goods" >
							所属线路：
							<view class="pop-input ">
								<uni-data-select
								@change="(e)=>{$routeData.SetNowRoute(e)}"
								:localdata="$routeData.getRoute()"
								v-model="add.data.route_id"
								placeholder="选择线路"
								placeholder-class="placeholder-class"
								></uni-data-select>
							</view>
						</view>
					</view>
					<view class="add-box" v-if="sendType=='kh' ">
						<view class="add-goods ">
							账号分组：
							<view class="pop-input " :title="$global.title.m31">
								<uni-data-select
								@change="(e)=>{$global.setStorageRoute('group',e)}"
								:localdata="$routeData.getGroup()"
								v-model="add.data.group_id"
								placeholder="选择账号分组"
								placeholder-class="placeholder-class"
								></uni-data-select>
							</view>
						</view>
					</view>
					
					<view class="add-box" v-if="sendType=='kh' ">
						<view class="add-goods">
							价格等级：
							<view class="pop-input " :title="$global.title.m31">
								<uni-data-select
								:localdata="$routeData.getLevel()"
								v-model="add.data.level_id"
								placeholder="选择价格等级"
								placeholder-class="placeholder-class"
								></uni-data-select>
							</view>
						</view>
					</view>
						
					<view class="add-box" >
						<view class="add-goods" >
							{{sendType=='yg' ?'账号名称：':'店铺名称：'}}
							<input 
							v-model="add.data.name" 
							 placeholder-class="placeholder-class"
							 placeholder="谨慎填写,打印会用到"
							class="pop-input " />
						</view>
					</view>
					<view class="add-box" v-if="sendType=='kh' || sendType=='gys'">
						<view class="add-goods" >
							真实姓名：
							<input 
							v-model="add.data.nickname" 
							 placeholder-class="placeholder-class"
							 placeholder="谨慎填写,打印会用到"
							class="pop-input " />
						</view>
					</view>
					<view class="add-box">
						<view class="add-goods">
							手机号码：
							<input  
							v-model="add.data.phone" 
							class="pop-input " 
							placeholder="选填"
							/>
						</view>
					</view>
					<view class="add-box" v-if="sendType=='kh' ">
						<view class="add-goods" >
							<view class="flex" style=" white-space: nowrap;">授信额度：</view>
							<view class="">
								<input
								v-model="add.data.debt" 
								class="pop-input "
								 placeholder-class="placeholder-class"
								type="number"
								placeholder="默认2000元授信,选填"
								 />
								 <view class="font12">
									客户的欠款超出此数值，将不允许继续进行下单消费、兑换
								 </view>
							</view>
						</view>
					</view>
					
					<view class="add-box">
						<view class="add-goods" >
							其他备注：
							<input
							v-model="add.data.descr" 
							class="pop-input " placeholder="选填"/>
						</view>
						
					</view>
					
						
					<view class="add-box">
						<view class="add-goods" >
							详细地址：
							
							<input class="pop-input " style="white-space: normal;" v-model="add.data.city" placeholder="选填"/>
							
							<view class="delete-ipu" @click="open_tx_lbs()">
								<img src="../../static/map/0f66e0.png"  ></img>
							</view>
						</view>
					</view>
					
					<!-- 地图 -->
					<view class="add-box" v-if="add.latlng.longitude>0">
						<!-- <iframe id="mapPage" width="100%" height="300px" frameborder=0
							:src="add.tx_latlng_url">
						</iframe> -->
						<map 
						class="map250"
						:longitude="add.latlng.longitude" 
						:latitude="add.latlng.latitude"
						:markers="add.markers"
						:show-compass="true" 
						:enable-zoom="true" 
						:enable-scroll="true" 
						:enable-poi="true"
						:enable-building="true"
						>
						<cover-view class="Navigation" @click="Navigation">导航到这里</cover-view>
						</map>
					</view>

					<view class="but-box" >
						<view class="but-boxs">
							<view @click="$refs.popup.close()"  class="add-but-close">
								取 消
							</view>
							<view @click="$common.noMultipleClicks('alterSure',alterSure)" class="add-but-com">
								{{add.update_id==0 ?'确 定 新 增':'保 存 修 改'}}
							</view>
							<view v-if="add.update_id > 0" @click="$common.noMultipleClicks('fun_Save_as',fun_Save_as)" class="add-but-com">
								另存为新增
							</view>
						</view>
					</view>
					
					<view class="tips">
						员工账号不能登陆小程序，客户账号不能登陆后台
					</view>
					<view class="tips">
						新增加的客户需要管理人员进行审核通过后方可登陆、下单等操作
					</view>
				</view>
			</view>
		</view>
		
	</uni-popup>
	<!-- end -->



	<!-- 单据页面 -->
	<uni-popup ref="page_money" type="center" :title="pageSend.name +' 单据'" width="90%">
		<order_money :OnPageSearchUid="pageSend.id"  class="h100"></order_money>
	</uni-popup>
	<!-- end -->
	
	<!-- 浏览的足迹页面 -->
	<uni-popup ref="goodsMarkRecord" type="center" :title="pageSend.name +' 浏览的足迹'"> 
		<goodsMarkRecord :OnPageSearch="pageSend.id"></goodsMarkRecord> 
	</uni-popup>
	<!-- end -->
	
	<!-- 商品记录页面 -->
	<uni-popup ref="pageUserGoodsRecord" type="center" :title="pageSend.name+' 商品购买的所有记录'">
		<userGoodsRecord :user_id="pageSend.id"  ></userGoodsRecord>
	</uni-popup>
	<!-- end -->

	<!-- 用户积分记录 -->
	<uni-popup ref="pageUserGoodsScore" type="center" :title="pageSend.name+' 积分变动记录'">
		<score_record  class="h100" :OnPageUserId="pageSend.id"></score_record> 
	</uni-popup>
	<!-- end -->

	<!-- 用户备忘录 -->
	<uni-popup ref="pageUserDescr" type="center" :title="pageSend.name+' 备忘录'" minHeight="auto" minWidth="auto">
		<user_descr :user_id="pageSend.id" class="h100" ></user_descr>
	</uni-popup>
	<!-- end -->
	
	<!-- 权限页面 -->
	<uni-popup ref="page_astrict" type="center" :title="pageSend.name +' 权限设置'">
		<user_astrict :OnPageSearch="pageSend.id" class="h100"></user_astrict>
	</uni-popup>
	<!-- end -->

	<!-- 地图 -->
	<uni-popup ref="tx_lbs" type="center" title="选择客户地点">
		<iframe id="mapPage" width="100%" height="100%" frameborder=0
			:src="'https://apis.map.qq.com/tools/locpicker?search=1&type=1&key='+position.lbs_key+'&referer=myapp'">
		</iframe>
	</uni-popup>
	<!--地图 end -->

	<!-- 用户数据页面 -->
	<uni-popup ref="userData" type="center" :title="pageSend.name+' 数据'">
		<user_data_all  class="h100" :OnPageSearchUid="pageSend.id"></user_data_all>  
	</uni-popup>
	<!--用户数据页面 end -->
	
	<!-- 用户单据流水页面 -->
	<uni-popup ref="verifyOrdero" type="center" :title="verifyOrdero.name +' 单据流水'">
		<verify_ordero  class="h100" :OnPageUserId="verifyOrdero.user_id"></verify_ordero> 
	</uni-popup>
	<!--用户单据流水页面 end -->


	
	<!-- 商品页面 -->
	<uni-popup ref="pageGoods" type="center" :title="pageSend.name">
		<shopping_admin :isPop="false" :disabled_uid="pageSend.id"  class="h100"></shopping_admin>
	</uni-popup>
	<!-- end -->
	
	

</view>
</template>

<script>
	import excel from "@/components/excel.vue"
	import xinjinheader from "@/components/xinjin-header/xinjin-header.vue"
	import pages from "@/components/admin-components/pages.vue"
	import empty from "@/components/admin-components/empty.vue"
	import user_astrict from "@/components/user/user_astrict.vue"
	import user_data_all from "@/components/user/user_data_all.vue"
	import verify_ordero from "@/components/verifyOrdero/verify_ordero.vue"
	import score_record from "@/components/scoreRecord/scoreRecord.vue"

	import userGoodsRecord from "@/components/userGoodsRecord/userGoodsRecord.vue"
	import goodsMarkRecord from "@/components/goodsMarkRecord/goodsMarkRecord.vue"

	import user_descr from "@/components/descr/user_descr.vue"
	export default{
		name:'person_admin',
		components: {
			user_descr,
			pages,
			xinjinheader,
			empty,
			user_astrict,
			user_data_all,
			verify_ordero,
			score_record,
			userGoodsRecord,
			goodsMarkRecord,
			excel
		},
		beforeCreate(){
			this.$options.components.order_money = require('@/components/admin-components/order_money.vue').default 
			
			this.$options.components.shopping_admin = require('@/components/goods/goods.vue').default 
		},
		data(){
			return{
				checkUpdate:{
					Mode:-1,//批量修改的模式
					isSelectAll:false,
					value:''
				},
				
				checkbox:{//多选框
					checkbox_status:[],
					select_all:false,
					select:false,
				},
				sumData:{
					getDebt:{
						value:'',
						status:''
					},
					getSales:{
						value:'',
						status:''
					},
					getScore:{
						value:'',
						status:''
					},
				},

				sort:{//排序方式
					value:'',
					index:0
				},
				firmUserSelect:{
					list:[
						{text:'销售客户',value:'0'},
						{text:'内部员工',value:'1'},
						{text:'供货商家',value:'2'},
					],
					nowId:'',
				},
				position:{//坐标位置
					lbs_key:'',//地图配置
				},
				pageSend:{//欲要传递到权限页面搜寻的内容
					name:'',
					id:''
				},
				verifyOrdero:{//需要传递到单据流水页面的参数
					name:'',
					user_id:''
				},
				updatePwssword:{//修改密码
					id:'',
				},
				page:{
					
					nowPage:1,//当前页数
					pageCount:1,//总页数
					maxCount:0,
					sum:0,
					pageCounts:15,
				},
				
				resData:{},
				TabcheckedIndex:-1,//当前选中的列表项
				add:{
					type:'',
					update_id:'0',//欲修改的ID
					markers:[],//用户标记点
					latlng:{//用户坐标点
						longitude:0,
						latitude:0,
					},//用于展示客户地点URL
					data:{
						group_id:'0',
						route_id:'',
						firm_user:'0',
						name:'',
						nickname:'',
						phone:'',
						descr:'',
						city:'',
						latlng:'',
						level_id:''
					}
				},
				
				headerSearch:{//左边的树形框 搜索
					route_id:'',//获取某个目录下的商品
					group_id:'0',
					level_id:'0',
					user_id:'',//指定用户
					word:''
				},
				//打点，期待格式[{date: '2019-06-27', info: '签到', data: { custom: '自定义信息', name: '自定义消息头',xxx:xxx... }}]
				signInData:{
					list:[]
				},//拜访记录
			
			}
		},
		 // 此处定义传入的数据
		props: {
		    OnPageSearchUserId: {
				type: String,
				default: ''
			},//其他页面传递进来直接搜寻的，不是菜单打开的
			status:{
				type: String,
				default: 'firm_user_list'
			},
			//gys  kh yg
			sendType:{
				type: String,
				default: 'kh'
			},
			OnLevelId:{
				type: String,
				default: '0'
			},
			OnGoruplId:{
				type: String,
				default: '0'
			},
			OnRouteId:{
				type: String,
				default: ''
			},
			OnSort:{
				type: String,
				default: ''
			},
			
			
		},
		
		created() {
		 
			let that = this
			
			if(this.OnPageSearchUserId != undefined && this.OnPageSearchUserId.length>0){
				this.headerSearch.user_id = this.OnPageSearchUserId
			}
			this.headerSearch.level_id = this.OnLevelId
			this.headerSearch.group_id = this.OnGoruplId
			this.headerSearch.route_id = this.OnRouteId
			this.sort.value = this.OnSort
			//读取地图配置
			uni.getStorage({
				key:'lbs',
				success:(res)=>{
					that.position.lbs_key = res.data.key
				}
			})
			if(this.sendType == 'gys'){
				this.add.data.route_id = "0"
				this.add.data.firm_user = "2"
				
			}
			if(this.sendType == 'yg'){
				this.add.data.firm_user = "1"
			}
			that.loadData(true);
		
		},
		methods:{
			checkUpdateOpen(mode){
				this.checkUpdate.Mode = mode
			},
			checkboxuserUpdateCheck(){
				var that = this
				uni.showModal({
					content: '是否确定进行批量操作？',
					success: function (res) {
						if (res.confirm) {
							var list  = []
							if(that.checkbox.checkbox_status.length<=0){
								var goodsIdArr = []
								 goodsIdArr.push(that.resData.list[that.TabcheckedIndex].id)
							}else{
								var goodsIdArr =  that.checkbox.checkbox_status
							}
							
							for(var i=0;i<goodsIdArr.length;i++){
								list.push({id:goodsIdArr[i]})
							}
							let JsonData = JSON.stringify(list)
							that.choos_all_close()
							that.$common.get_request(
								{
									type:'userUpdateCheck',
									value:JsonData,
									id:that.checkUpdate.value,
									mode:that.checkUpdate.Mode
								},
								(res)=>{
									that.loadData(true)
								},()=>{
									
								
								},true,"","操作中..."
							);
							
							that.checkUpdate.Mode = -1
						}
					}
				});
			},
			
			/**
			 * 回调当前选中的表项
			*/
			checkbox_change(e){
				this.checkUpdate.isSelectAll = e.detail.value.length>=2 ? true :false
				this.checkbox.checkbox_status = e.detail.value
			},
			/**
			 * 全选中
			*/
			choose_all(){
				//console.log("choose_all")
				this.checkbox.checkbox_status = []
				if(this.checkbox.select_all == false){
					this.checkbox.select_all  = true
					this.checkbox.select      = true
					this.checkUpdate.isSelectAll          = true
					for (var i=0;i<this.resData.list.length;i++) {
						this.checkbox.checkbox_status.push(this.resData.list[i].id)
					}
			
				}else{
					this.choos_all_close()
				}
			},
			
			// 取消全选中
			choos_all_close(){
				this.checkbox.select_all = false
				this.checkbox.checkbox_status = []
				this.checkbox.select = false
				this.checkUpdate.isSelectAll = false
			},
			//获取总数类
			GetSum(type){
				var that = this
				
				this.sumData.getDebt.status  = ''
				this.sumData.getSales.status = ''
				this.sumData.getScore.status = ''
				
				if(type=='getDebt'){
					this.sumData.getDebt.status = 1
					
					var body = this.GetBody(true)
					this.$common.get_request(
						body,(res)=>{
							if(res.valueData){
								that.sumData.getDebt.value = res.valueData
							}
						}
					);
					
				}else if(type=='getSales'){
					this.sumData.getSales.status = 1
					
					var body = this.GetBody(true)
					this.$common.get_request(
						body,(res)=>{
							if(res.valueData){
								that.sumData.getSales.value = res.valueData
							}
						}
					);
					
				}else if(type=='getScore'){
					this.sumData.getScore.status = 1
					
					var body = this.GetBody(true)
					this.$common.get_request(
						body,(res)=>{
							if(res.valueData){
								that.sumData.getScore.value = res.valueData
							}
						}
					);
					
				}else{
					this.sumData.getScore.value = ''
					this.sumData.getDebt.value  = ''
					this.sumData.getSales.value = ''
				}
				
			},
			
			openGoodsDisabled(name,id){
				this.pageSend.name = name 
				this.pageSend.id   = id
				this.$refs.pageGoods.open()
			},

		 	//打开拜访
			openCalendar(user_id){
				var that = this
				that.$common.get_request(
					{type:'getSignIn',user_id:user_id},
					(res)=>{
						that.signInData = res
						that.$refs.calendar.open();
					}
				);
			},
		 	//发起搜索
			searchBut(){
				this.sort.value = ""
				this.sort.index = 0
				this.loadData(true)
			},
		 	//开始打开地理位置
			Navigation(e){
				if(this.add.latlng.latitude == '' || this.add.latlng.longitude==''){
					this.$common.toast("此用户未设置地理位置")
					return
				}
				this.poimarker(this.add.latlng.latitude,this.add.latlng.longitude,this.add.data.name,this.add.data.city,this.position.lbs_key)
			},
		 	//打开坐标位置
		 	poimarker(latitude,longitude,UerName,CityName,MapKey){
		 		let marker = `coord:${latitude},${longitude};title:${UerName};addr:${CityName}`
		 		let Url    = `https://apis.map.qq.com/tools/poimarker?type=0&marker=${marker}&key=${MapKey}&referer=myapp`
				
		 		window.open(Url)
		 		return;
		 	},
			/**
			 * 腾讯地图选择位置后的回调
			*/
			fun_onLbs(event){
				var that = this
				// 接收位置信息，用户选择确认位置点后选点组件会触发该事件，回传用户的位置信息
				if (event && event.data &&  event.data.module == 'locationPicker') {
					var loc = event.data;
					//防止其他应用也会向该页面post信息，需判断module是否为'locationPicker'
					if('我的位置' == loc.poiname){
						return
					}
					that.add.data.city   = loc.poiname+"-"+loc.poiaddress
					that.add.data.latlng = JSON.stringify(loc.latlng)
					that.open_tx_lbs(true)
				}
			},
			/**
			 * 弹出单据流水
			*/
			openPageVerifyOrdero(name,user_id){
				this.verifyOrdero.name = name
				this.verifyOrdero.user_id = user_id
				this.$refs.verifyOrdero.open()
			},
			
			/**
			 * 弹出/关闭地图窗口
			*/
			open_tx_lbs(isclose=false){
				var that = this
				if(isclose==true ){
					this.$refs.tx_lbs.close()
					
					window.removeEventListener('message',that.fun_onLbs,false);
					return
				}
				this.$refs.tx_lbs.open()
				window.addEventListener('message', that.fun_onLbs, false);
			},
			/**
			 * 弹出权限窗口
			*/
			openPageAstrict(name,uid){
				this.pageSend.name = name
				this.pageSend.id = uid
				this.$refs.page_astrict.open()
			},
			/**
			 * 弹出单据窗口
			*/
			openPageMoney(name,uid){
				this.pageSend.name = name
				this.pageSend.id = uid
				this.$refs.page_money.open()
				
			},
			/**
			 * 弹出浏览足迹界面
			 * 
			*/
			openGoodsMarkRecord(name,uid){
				this.pageSend.name = name
				this.pageSend.id = uid
				this.$refs.goodsMarkRecord.open()
			},
			/**
			 * 弹出更多操作按钮
			*/
			openActionSheet(item,index,event){
				var that = this
				var itemList = [];
				itemList.push("修改密码")
				if(item.prevent==3){
					itemList.push("通过审核")
					
				}else if(item.prevent==2){
					itemList.push("启用账号")
					
				}else if(item.prevent==1){
					itemList.push("禁用账号")
					
				}else{
					that.$common.showModal("失败，系统出错！生成弹出菜单失败")
					return ;
				}
				itemList.push("删除账号")
				itemList.push("初始化积分")
				//console.log(event)
				uni.showActionSheet({
					itemList:itemList,
					popover:{
						left:event.detail.x,
						top:event.detail.y,
					},
					success: (res) => {
						var tapIndex = res.tapIndex
						//构建数组
						if(that.checkbox.checkbox_status.length<=0){
							var uidList = [];
							uidList.push(that.resData.list[that.TabcheckedIndex].id)
						}else{
							var uidList =  that.checkbox.checkbox_status
						}
						if(uidList.length<=0){
							return
						}
						
						if(tapIndex == 0){//修改密码
							that.$routeData.firm_user_password(item.id,false)
							return
						}
						else if(tapIndex == 1){//通过审核/封禁
							that.menuLib(tapIndex,uidList)
							return
						}
						else if(tapIndex == 2){//删除账号
							uni.showModal({
								content: '是否确定删除？此操作不可逆。删除后有关信息无法恢复！',
								success: function (res) {
									if (res.confirm) {
										that.menuLib(tapIndex,uidList)
									}
								}
							});
						}
						else if(tapIndex == 3){
							uni.showModal({
								content: '是否确定清空用户的积分记录？此操作不可逆。删除后有关信息无法恢复！',
								success: function (res) {
									if (res.confirm) {
										that.menuLib(tapIndex,uidList)
									}
								}
							});
						}
						
					}
				})
			},
			menuLib(tapIndex,uidList){
				var that = this
				if(uidList.length<=0){
					that.loadData(true)
					return
				}
				var user_id = uidList[0];
				var tmp_uidList = JSON.parse(JSON.stringify(uidList))
				tmp_uidList.splice(0,1)
				if(tapIndex == 1){
					that.$common.get_request(
						{
							type:'firm_user_prevent',
							uid:user_id,
						},
						(res)=>{
							that.$common.toast(res.msg)
							that.menuLib(tapIndex,tmp_uidList)
						}
					);
				}
				if(tapIndex == 2){
					that.$common.get_request(
						{type:'delete_user',user_id:user_id},
						(res)=>{
							that.$common.toast(res.msg)
							that.menuLib(tapIndex,tmp_uidList)
						}
					);
				}
				if(tapIndex == 3){
					that.$routeData.UserResetScore(user_id,()=>{
						that.menuLib(tapIndex,tmp_uidList)
					})
				}
				
			},
			/**
			 * 弹出用户积分
			*/
			openPageUserScore(name,uid){
				this.pageSend.name = name
				this.pageSend.id = uid
				this.$refs.pageUserGoodsScore.open()
			},
			/**
			 * 弹出用户购买商品的所有数据
			*/
			openPageUserGoodsRecord(name,uid){
				this.pageSend.name = name
				this.pageSend.id = uid
				this.$refs.pageUserGoodsRecord.open()
			},
			/**
			 * 弹出备忘录
			*/
			openPageUserDescr(name,uid){
				this.pageSend.name = name
				this.pageSend.id = uid
				this.$refs.pageUserDescr.open()
			},
			/**
			 * 弹出用户数据
			*/
			openPageUserData(name,uid){
				this.pageSend.name = name
				this.pageSend.id = uid
				this.$refs.userData.open()
			},
			
			

			/**
			 * 分页器回调
			 * 
			*/
			updatePage(pageName,pageCount){
				var that = this
			
				that.page.nowPage = pageName
				that.page.pageCounts = pageCount
				that.loadData(false)
			},
			/**
			 * 用户的禁用与启用
			 * 
			*/
			userPrevent(index){
				var that = this
				that.$common.get_request(
					{type:'firm_user_prevent',uid:that.resData.list[index].id},
					(res)=>{
						that.resData.list[index].prevent = res.prevent
						that.$common.toast("更改成功")
					}
				);
			},
			
			/**
			 * 批量通过用户审核
			 * 
			*/
			batchPrevent(){
				
				var that = this
				var jsonData = [];
				that.resData.list.forEach((item)=>{
					jsonData.push(item.id)
				})
				var data = JSON.stringify(jsonData)
				that.$common.get_request(
					{type:'firmUserPreventBatch',data:data},
					(res)=>{
						that.loadData(true);
					}
				);
			},

			/**
			 * 查看线路
			*/
			onclickRoute(id){
				let tmpArr = this.$routeData.getRoute()
				for (var i=0;i<tmpArr.length;i++) {
					if(tmpArr[i].value == id){
						return tmpArr[i].text
					}
				}
				return '-'
			},
			
			/**
			 * 查看线路
			*/
			onclickGroup(id){
				let tmpArr = this.$routeData.getGroup()
				for (var i=0;i<tmpArr.length;i++) {
					if(tmpArr[i].value == id){
						return tmpArr[i].text
					}
				}
				return '-'
			},
			formsubmitLevel(e){
				this.headerSearch.word  = ''
				this.headerSearch.level_id = e
				this.loadData()
			},
			/**
			 * 分类插件回调返回
			*/
			formsubmit(e){
				this.headerSearch.word  = ''
				this.page.nowPage = 1//初始化页码
				this.headerSearch.route_id = e
				this.searchBut()
			},
			
			/**
			 * 分类插件回调返回
			*/
			formsubmitGroup(e){
				this.headerSearch.word  = ''
				this.page.nowPage = 1//初始化页码
				this.headerSearch.group_id = e
				this.searchBut()
			},
			GetBody(isUpdatePage){
				this.page.nowPage = isUpdatePage == true ? 1:this.page.nowPage;
				return {
						type:this.status,
						search:this.headerSearch.word,//搜索内容
						pages:this.page.nowPage,//当前位于页数
						page_count:this.page.pageCounts,//当前请求页的数量
						route_id: this.sendType!='kh' ? '': this.headerSearch.route_id,//获取某个目录下的商品
						group_id: this.headerSearch.group_id,//获取某个目录下的商品
						level_id: this.headerSearch.level_id,//获取某个目录下的商品
						user_type:this.sendType,
						sort:this.sort.value,//排序方式
						user_id: this.headerSearch.word.length==0 ? this.headerSearch.user_id:'',//指定用户搜索
						getDebt:this.sumData.getDebt.status,
						getSales:this.sumData.getSales.status,
						getScore:this.sumData.getScore.status,
					};
			},
			/**
			 * 读取用户
			 * type : goods_list|goods_search
			 * 
			*/
			loadData(isUpdatePage=true,ReqExport=0){
				var that = this
				that.TabcheckedIndex=0//初始化列表选中项
				that.choos_all_close()
				this.GetSum('')
				var body = this.GetBody(isUpdatePage)
				that.$common.get_request(
					body,(res)=>{
						
						that.page.sum  = res.sum
						if(isUpdatePage == true){
						that.page.nowPage  = 1
						}
						
						
						
						 
						 that.resData = res
						 
						 if(res.list.length>0){
							 that.TabcheckedIndex = 0
						 }else{
							 that.TabcheckedIndex = -1
						 }
					}
				);
			},
			
			/**
			 * 另存为新增
			*/
			fun_Save_as(){
				this.add.update_id='0'//改变这个就可以作为新增了
				this.add.type = 'user_add'
				this.alterSure()
			},
			/**
			 * 客户-发送增加、修改
			*/
			alterSure(){
				var that = this
				if(that.add.data.name==null  || that.add.data.name.length==0){
					that.$common.toast("未填写店铺名称")
					return
				}
					
				if(that.sendType=='kh' || that.sendType=='gys'){
					if(that.add.data.nickname==null  || that.add.data.nickname.length==0){
						that.$common.toast("未填写客户名字名称")
						return
					}
				}
				// if(that.add.data.phone==null  || that.add.data.phone.length==0){
				// 	that.$common.toast("未填写客户手机号码")
				// 	return
				// }
				if(that.add.data.route_id==null  || that.add.data.route_id.length==0){
					if(that.status=='firm_user_list' && that.sendType=='kh'){
						if(this.$routeData.getRoute().length>0){
							that.$common.toast("未选择所属线路")
							return
						}
					}
				}
				uni.showModal({
					content: '是否确定增加或修改？',
					success: function (res) {
						if (res.confirm) {
							let body = {}
							body = that.add.data
							body.update_id = that.add.update_id
							body.type = that.add.type
							that.$common.get_request(
								body,
								(res)=>{
									that.$refs.popup.close();//关闭弹窗
									that.loadData(true)
								}
							);
						}
					}
				});
			},
			/**
			 * 编辑某条用户
			 * 
			*/
			alter(e,index){
				var that = this
				let latlng = e.latlng
				if(latlng != ''){
					latlng = JSON.parse(latlng)
					that.add.latlng.latitude = latlng.lat
					that.add.latlng.longitude = latlng.lng
					that.createMarkersUser(that.add.latlng,e.id,e.name,'../../static/map/dingwei.png')
					// let marker = `coord:${latlng.lat},${latlng.lng};title:${e.name};addr:${e.city}`
					// that.add.tx_latlng_url = `https://apis.map.qq.com/tools/poimarker?type=0&marker=${marker}&key=${that.position.lbs_key}&referer=myapp`
					
				}else{
					that.add.latlng.latitude  = ""
					that.add.latlng.longitude = ""
				}
				
				that.add.type = 'user_update'
				// that.add.id   = e.id
				that.add.update_id   = e.id
				let tmp =  that.resData.list[index]
				that.add.data      =  JSON.parse( JSON.stringify(tmp) ) //避免变量赋值后双向绑定
				that.$refs.popup.open()
			},
			
			/**
			 * 创建用户标记点 */
			createMarkersUser(location,user_id,username,avatar) {
				var that = this
				let markers_tmp = []
				let markerItem = {
					id: parseFloat(user_id),
					latitude: location.latitude,
					longitude: location.longitude,
					iconPath: avatar,
					width: '0px',
					height: '0px',
					callout:{
						bgColor:'#333',
						color:'#fff',
						content: username,
						display: 'ALWAYS',//'BYCLICK':点击显示; 'ALWAYS':常显
						borderRadius:10,
						padding:5,
					},
				}
				markers_tmp.push(markerItem)//加入用户标记点数组
				this.add.markers = markers_tmp
				
			},
			
			/**
			 * 打开增加窗口
			 * 
			*/
			addShow(){
				var that = this

				this.add.update_id = ''
				this.add.type='user_add'
				this.$refs.popup.open()
			},
		}
	}
</script>

<style>
	.add-goods{
		width: 100%;
	}
</style>
